﻿namespace Infrastructure.Domain
{
    public abstract class EntityBase : IEntity 
    {
        public long Id { get; set; }

        public override bool Equals(object entity)
        {
            var equal = entity != null
                               && entity is EntityBase
                               && this == (EntityBase)entity;

            return equal;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public static bool operator ==(EntityBase entity1, EntityBase entity2)
        {
            if ((object)entity1 == null && (object)entity2 == null)
                return true;

            if ((object)entity1 == null || (object)entity2 == null)
                return false;

            if (entity1.Id.ToString() == entity2.Id.ToString())
                return true;

            return false;
        }

        public static bool operator !=(EntityBase entity1, EntityBase entity2)
        {
            return (!(entity1 == entity2));
        }
    }

}
